package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * @param categoryId:
     * @return Integer
     * @description 根据分类id查询菜品数量
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);


    /**
     * @param dish:
     * @return void
     * @description 新增菜品
     */
    @AutoFill(value=OperationType.INSERT)
    void insert(Dish dish);

    /**
     * @param dishPageQueryDTO:
     * @return Page<DishVO>
     * @description 菜品分页查询
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * @param id:
     * @return Dish
     * @description 根据主键查询菜品
     */

    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * @param id:
     * @return void
     * @description 根据主键删除菜品数据
     */
    @Delete("delete from dish where id = #{id}")
    void deleteById(Long id);

    /**
     * @param dish:
     * @return void
     * @description 根据id动态修改菜品数据
     */
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);


    /**
     * @param id:
     * @return List<Dish>
     * @description 根据套餐id查询套餐中包含哪些菜品
     */
    @Select(" select * from dish where id in (select dish_id from setmeal_dish where setmeal_id = #{setmealId})")
    List<Dish> getBySetmealId(Long id);

    /**
     * @param queryDTO:
     * @return List<Dish>
     * @description 根据分类id查询菜品
     */
    List<Dish> page(DishPageQueryDTO queryDTO);

    /**
     * @param dish :
     * @return List<Dish>
     * @description 条件查询菜品和口味
     */

    List<DishVO> listWithFlavor(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
